package com.greensecurity.sim.service.impl;

import com.greensecurity.sim.entity.Green;
import com.greensecurity.sim.repository.GreenRepository;
import com.greensecurity.sim.service.GreenService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service
public class GreenServiceImpl implements GreenService {
    @Resource
    private GreenRepository greenRepository;

    @Override
    public String save(Green green) {
        greenRepository.save(green);
        return "保存成功";
    }

    @Override
    public String getInterNum(String dateTime){
       return greenRepository.getInterNun(dateTime);
    }


    @Override
    public long findByInterNum(String interNum){

        return greenRepository.findByInterNum(interNum);
    }

    public List<Green> findAll(){
        return greenRepository.findAll();
    }

    public List<Green> findGreenLimit(){
        return greenRepository.findGreenLimit();
    }

    public void delByInterNum(Long id){
        greenRepository.deleteGreendKey(id);
        greenRepository.deleteById(id);
    }

    public Optional<Green> findGreenById(Long id){
        return greenRepository.findById(id);
    }
}
